<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>系统设置</title>
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/static/img/favicon.ico}" media="screen"/>
    <link rel="stylesheet" th:href="@{/static/css/layui.css}" media="all"/>
</head>
<style>
    .layui-form-pane .layui-form-label{
        width: 120px;
    }
</style>
<body>

<div style="margin:5px;">
    <form class="layui-form layui-form-pane" action="" lay-filter="val-filter">
        <div class="layui-form-item">
            <label class="layui-form-label" pane>数据加载</label>
            <div class="layui-input-inline">
                <select name="initDataSource" id="initDataSource">
                    <option value="1">开启</option>
                    <option value="2">关闭</option>
                </select>
                <input type="hidden" name="id" th:value="${obj.id}">
                <input type="hidden" id="initDataSourceVal" th:value="${obj.initDataSource}">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right1">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" pane>日志记录</label>
            <div class="layui-input-inline">
                <select name="enabledSqlLog" id="enabledSqlLog">
                    <option value="1">开启</option>
                    <option value="2">关闭</option>
                </select>
                <input type="hidden" id="enabledSqlLogVal" th:value="${obj.enabledSqlLog}">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right2">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" pane>锁屏展示</label>
            <div class="layui-input-inline">
                <select name="enabledLockView" id="enabledLockView">
                    <option value="0">开启</option>
                    <option value="1">关闭</option>
                </select>
                <input type="hidden" id="enabledLockViewVal" th:value="${obj.enabledLockView}">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right3">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" pane>文档展示</label>
            <div class="layui-input-inline">
                <select name="enabledHelp" id="enabledHelp">
                    <option value="0">开启</option>
                    <option value="1">关闭</option>
                </select>
                <input type="hidden" id="enabledHelpVal" th:value="${obj.enabledHelp}">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right4">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" pane>提示信息</label>
            <div class="layui-input-inline">
                <select name="enabledHint" id="enabledHint">
                    <option value="0">开启</option>
                    <option value="1">关闭</option>
                </select>
                <input type="hidden" id="enabledHintVal" th:value="${obj.enabledHint}">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right8">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" pane>windows通知</label>
            <div class="layui-input-inline">
                <select name="enabledNotification" id="enabledNotification">
                    <option value="0">开启</option>
                    <option value="1">关闭</option>
                </select>
                <input type="hidden" id="enabledNotificationVal" th:value="${obj.enabledNotification}">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right9">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label" pane>分页条数</label>
            <div class="layui-input-inline" style="width: 400px;">
                <input type="text" id="pageLimitMax" name="pageLimitMax" th:value="${obj.pageLimitMax}"
                       lay-affix="number"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right5">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" pane>语句限制</label>
            <div class="layui-input-inline" style="width: 400px;">
                <input type="text" id="riskText" name="riskText" th:value="${obj.riskText}" class="layui-input"
                       lay-affix="clear">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right6">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" pane>失败次数</label>
            <div class="layui-input-inline" style="width: 400px;">
                <input type="text" id="failLogin" name="failLogin" th:value="${obj.failLogin}" lay-affix="number"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-text-em" lay-on="tips-right7">
                <i class="layui-icon layui-icon-tips"></i>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-primary layui-border-green" lay-submit lay-filter="save">
                    <i class="layui-icon layui-icon-add-1"> </i>保存设置
                </button>

                <button class="layui-btn layui-btn-primary layui-border-red"
                        onclick="btnPost('清除SQL执行日志','logManager/deleteLog/1');return false;">
                    <i class="layui-icon layui-icon-clear"> </i>清空SQL执行记录
                </button>

                <button class="layui-btn layui-btn-primary layui-border-red"
                        onclick="btnPost('清除用户登陆日志','logManager/deleteLog/2');return false;">
                    <i class="layui-icon layui-icon-clear"> </i>清空登陆系统记录
                </button>

                <button class="layui-btn layui-btn-primary layui-border-red"
                        onclick="btnPost('清除作业日志','timingManager/jobLogDelete');return false;">
                    <i class="layui-icon layui-icon-clear"> </i>清空作业执行记录
                </button>

                <button class="layui-btn layui-btn-primary layui-border-red"
                        onclick="btnPost('清除SQL常用记录','sqlManager/sqlTextDeleteAll');return false;">
                    <i class="layui-icon layui-icon-clear"> </i>清空SQL常用列表
                </button>

            </div>
        </div>
    </form>
</div>
<script th:src="@{/static/layui.js}"></script>
<script th:replace="~{base::ctx}"/>
<script>

    layui.use(function () {
        const layer = layui.layer;
        const form = layui.form;
        const $ = layui.jquery;
        const util = layui.util;

        $("#initDataSource").each(function () {
            $(this).children("option").each(function () {
                if (this.value === $("#initDataSourceVal").val()) {
                    $(this).attr("selected", "selected");
                }
            });
        });
        $("#enabledSqlLog").each(function () {
            $(this).children("option").each(function () {
                if (this.value === $("#enabledSqlLogVal").val()) {
                    $(this).attr("selected", "selected");
                }
            });
        });

        $("#enabledLockView").each(function () {
            $(this).children("option").each(function () {
                if (this.value === $("#enabledLockViewVal").val()) {
                    $(this).attr("selected", "selected");
                }
            });
        });

        $("#enabledHelp").each(function () {
            $(this).children("option").each(function () {
                if (this.value === $("#enabledHelpVal").val()) {
                    $(this).attr("selected", "selected");
                }
            });
        });

        $("#enabledHint").each(function () {
            $(this).children("option").each(function () {
                if (this.value === $("#enabledHintVal").val()) {
                    $(this).attr("selected", "selected");
                }
            });
        });

        $("#enabledNotification").each(function () {
            $(this).children("option").each(function () {
                if (this.value === $("#enabledNotificationVal").val()) {
                    $(this).attr("selected", "selected");
                }
            });
        });

        form.render();

        // 提示信息
        const tipsConfig = {tips: [2, '#16b777']};//{tips: [2, '#16b777']};
        util.on('lay-on', {
            'tips-right1': function () {
                layer.tips('开启时，启动项目时会主动加载数据源，启动速度慢，受链接失败影响。<br>关闭时，项目启动不会加载数据源，需要手动加载数据源，启动速度快，不会受链接失败影响。', this, tipsConfig);
            },
            'tips-right2': function () {
                layer.tips('开启时，执行SQL会记录SQL执行日志及返回结果，时间长会增大数据库文件;<br>关闭时,不记录SQL执行日志，会缺失操作记录找不到操作人。', this, tipsConfig);
            },
            'tips-right3': function () {
                layer.tips('开启时会显示锁屏按钮，且需要输入密码重新进入;<br>关闭时会隐藏锁屏按钮', this, tipsConfig);
            },
            'tips-right4': function () {
                layer.tips('开启时会显示帮助按钮;<br>关闭时会隐藏帮助按钮', this, tipsConfig);
            },
            'tips-right5': function () {
                layer.tips('默认查询时分页最大查询条数<br>SQL执行时没有分页条件会走此限制,sql中有分页条件不会走此限制<br>填0不开启此限制。<br>支持mysql、oracle、H2、postgres、达梦、人大金仓、神州通用', this, tipsConfig);
            },
            'tips-right6': function () {
                layer.tips('执行SQL时检查语句包含危险关键词不允许执行;<br>小写输入关键词支持多个用,分割', this, tipsConfig);
            },
            'tips-right7': function () {
                layer.tips('账号登录失败次数,超过次数状态将被禁用!<br>普通账号使用超管账号修改用户状态<br>admin账号重置密码 <a target="_blank" href="https://gitee.com/boy_0214/websql/wikis/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98">gitee Wiki</a>', this, tipsConfig);
            },
            'tips-right8': function () {
                layer.tips('编辑器写SQL时会提示选中的数据源所有表及字段!<br>如果数据库中超过上万字段不建议开启会卡死!<br>支持mysql、oracle、H2、postgres、达梦、人大金仓、神州通用', this, tipsConfig);
            },
            'tips-right9': function () {
                layer.tips('执行SQL完成后,页面离开态会进行Windows系统通知!<br>关闭将不会在发送通知，但不影响执行SQL使用。', this, tipsConfig);
            }
        })

        form.on('submit(save)', function (data) {
            const field = data.field;
            window.localStorage.removeItem('site');
            post(ctx + "settingManager/updateSysSetUp", field, (res) => {
                layer.msg(res.msg, {icon: res.code === 200 ? 1 : 2});
            });
            return false;
        });


    });

    /**
     * 按钮请求后台操作
     * @param msg
     * @param url
     */
    function btnPost(msg, url) {
        layer.confirm("确认" + msg + "？", function () {
            post(ctx + url, null, (res) => {
                layer.msg(res.msg, {icon: res.code === 200 ? 1 : 2});
            });
        });
    }
</script>
</body>
</html>